package ge.gen.eBdgt.persistence;

import ge.gen.eBdgt.db.DBConn;
import ge.gen.eBdgt.vo.PlanToActualsVO;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

public class PlanToActualsDao implements PlanToActualsImplDao {
	DBConn conn;
	private Statement stmt;

	public PlanToActualsDao() throws Exception {
		conn = new DBConn(getDBName());
		stmt = conn.getStatement();
		conn.setAutoCommit(true);
	}

	public String getDBName() {
		return "c:\\temp\\test.mdb";
	}

	@Override
	public List getPlanToActualsVOList(String orderNo) throws Exception {
		List planToActualsVOList = new ArrayList<PlanToActualsVO>();
		String query = "SELECT ORDER_NO, FW,CUMM_PLAN_HRS,CUMM_ACTUAL_HRS  FROM TBL_PLAN_TO_ACTUALS WHERE ORDER_NO='" + orderNo + "' ORDER BY FW ASC";
		System.out.println(query);
		if (stmt.execute(query)) {
			ResultSet rs = stmt.getResultSet();
			if (rs != null) {
				planToActualsVOList = new ArrayList<PlanToActualsVO>();
				while (rs.next()) {
					planToActualsVOList.add(generatePlanToActuals(rs));
				}
			}
		}
		return planToActualsVOList;
	}

	private PlanToActualsVO generatePlanToActuals(ResultSet rs) throws SQLException {
		ArrayList<String> list = new ArrayList<String>();
		list.add(rs.getString("ORDER_NO"));
		list.add(rs.getString("FW"));
		list.add(rs.getString("CUMM_ACTUAL_HRS"));
		list.add(rs.getString("CUMM_PLAN_HRS"));
		return new PlanToActualsVO(list);
	}
}
